package com.xneure.utils.cns;

import java.util.HashMap;
import java.util.Map;

public class KeywordVerify {
	Map<Character, CharFilter> charFilters;

	public void add(String str) {
		if (null == charFilters) {
			charFilters = new HashMap<Character, CharFilter>(str.length() * 2);
		}
		CharFilter cf = charFilters.get(str.charAt(0));
		if (null == cf) {
			charFilters.put(str.charAt(0), new CharFilter(str));
		} else {
			cf.append(str);
		}
	}

	public boolean verify(String str) {
		CharFilter cf = charFilters.get(str.charAt(0));
		if (null == cf) {
			return false;
		} else {
			return cf.verify(str);
		}
	}

	public static void main(String[] args) {
		KeywordVerify kVerify = new KeywordVerify();
		kVerify.add("abcdefg");
		kVerify.add("abcfg");
		System.out.println(kVerify.verify("abcfg"));
		System.out.println(kVerify.verify("abc"));
	}
}
